from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage


def pageData(modelDemo, Demo_serializer, page, limit):
    try:
        paginator = Paginator(modelDemo, limit)
        obj = paginator.page(page)
    except PageNotAnInteger:
        obj = paginator.page(1)
    except EmptyPage:
        obj = paginator.page(paginator.num_pages)

    res = Demo_serializer(obj, many=True)
    count = paginator.count
    return res, count
